package com.eduagent.xwqeduagent.controller;


import com.eduagent.xwqeduagent.app.agent.OnlineSearch;
import com.eduagent.xwqeduagent.model.dto.ChatDTO;
import com.eduagent.xwqeduagent.model.vo.ChatEventVO;
import com.eduagent.xwqeduagent.model.vo.OnlineSearchResultVO;
import com.eduagent.xwqeduagent.service.ChatService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

@Slf4j
@RestController
@RequestMapping("/chat")
@RequiredArgsConstructor
public class ChatController {

    private final ChatService chatService;

    /**
     * 学生端助手对话
     * @param chatDTO
     * @return
     */
    @PostMapping(produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<ChatEventVO> chat(@RequestBody ChatDTO chatDTO) {
        return this.chatService.chat(chatDTO.getQuestion(), chatDTO.getSessionId());
    }

    /**
     * 打断ai助手的回答
     * @param sessionId
     */
    @PostMapping("/stop")
    public void stop(@RequestParam("sessionId") String sessionId) {
        this.chatService.stop(sessionId);
    }


    @PostMapping("/text")
    public String chatText(@RequestParam String question,  @RequestParam String sessionId) {
        return this.chatService.chatText(question,  sessionId);
    }

}
